import functools

nums = [1, 2, 3, 4, 5]
product = functools.reduce(lambda x, y: x * y, nums)
print("product=", product)


def decorate_fun(fun):

    @functools.wraps(fun)
    def wrapper(*args, **kwargs):
        print("before", args, "kwargs=", kwargs)
        print(f"调用函数: {fun.__name__}")
        fun(*args, **kwargs)
        print("after")

    return wrapper


@decorate_fun
def say_hello(name):
    print(f"hello {name}")


say_hello("jackie")
# wrapper_fun("jackie")


# 'must define at least one ordering operation: < > <= >=')
@functools.total_ordering
class Student:

    def __init__(self, name, score):
        self.name = name
        self.score = score

    def __eq__(self, stuInstance):
        return self.score == stuInstance.score

    def __lt__(self, stuInstance):

        return self.score < stuInstance.score

    def __gt__(self, stuInstance):
        return self.score > stuInstance.score

    # 定义对象的字符串表示
    def __repr__(self):
        return f"Student({self.name}, {self.score})"


stu1 = Student("linda", 20)
stu2 = Student("susan", 50)
stu3 = Student("lucy", 30)
stu4 = Student("smith", 89)
# 创建学生对象列表
students = [
    Student("Alice", 85),
    Student("Bob", 92),
    Student("Charlie", 78),
    stu1,
    stu2,
    stu3,
    stu4,
]
sort_stu = sorted(students, reverse=True)
print("desc:", sort_stu)

new_sort_stu = sorted(students, key=lambda stu: stu.score)

print("asec:", new_sort_stu)
